// vim: foldmethod=marker : foldmarker=<<<,>>>
/*
 File: entry.c
 Generated-From: entry.nw
*/
#include "hooverPch.h"

#include "nis/entry.h"
#define POOL_SIZE 2048

hidden_q v_t spellSystemTime(PCWSTR prefix, WCHAR ** p, i_p avail, SYSTEMTIME * st) {
 WCHAR buf[128]; is_t aux;

 aux=_snwprintf(*p,*avail,L"%s",prefix); if (aux<0) goto exit0;
 (*p)+=aux; (*avail)-=aux;

 GetDateFormat(LOCALE_USER_DEFAULT,DATE_SHORTDATE,st,NULL,buf,128);
 aux=_snwprintf(*p,*avail,L" %s",buf); if (aux<0) goto exit0;
 (*p)+=aux; (*avail)-=aux;

 GetTimeFormat(LOCALE_USER_DEFAULT,0,st,NULL,buf,128);
 aux=_snwprintf(*p,*avail,L" %s\r\n",buf); if (aux<0) goto exit0;
 (*p)+=aux; (*avail)-=aux;

exit0: **p=0;
 };

// getEvent <<<
hidden_q PCWSTR getEvent(DWORD event) {
 switch (event) {
 case NOTIFICATION_EVENT_DEVICE_CHANGE: 
  return L"a PC Card device changed";
/* case NOTIFICATION_EVENT_INTERNET_PROXY_CHANGE:
  return L"the Internet Proxy used by the device has changed";*/
 case NOTIFICATION_EVENT_IR_DISCOVERED:
  return L"the device discovered a server by using infrared communications";
 case NOTIFICATION_EVENT_NET_CONNECT: 
  return L"the device connected to a network";
 case NOTIFICATION_EVENT_NET_DISCONNECT: 
  return L"the device disconnected from a network";
 case NOTIFICATION_EVENT_NONE: 
  return L"no events occurred. Remove all event registrations for this application";
 case NOTIFICATION_EVENT_OFF_AC_POWER: 
  return L"the user turned the alternating current (AC) power off";
 case NOTIFICATION_EVENT_ON_AC_POWER: 
  return L"the user turned the AC power on";
 case NOTIFICATION_EVENT_RESTORE_END: 
  return L"a full device data restore completed";
 case 14/*NOTIFICATION_EVENT_RNDIS_FN_DETECTED*/: 
  return L"RNDISFN interface is instantiated";
 case NOTIFICATION_EVENT_RS232_DETECTED: 
  return L"an RS232 connection was made";
 case NOTIFICATION_EVENT_SYNC_END: 
  return L"data synchronization finished";
 case NOTIFICATION_EVENT_TIME_CHANGE: 
  return L"the system time changed";
 case NOTIFICATION_EVENT_TZ_CHANGE: 
  return L"the time zone changed";
 case NOTIFICATION_EVENT_WAKEUP: 
  return L"the device woke up";
  };
 return NULL;
 };
// >>>

hidden_q v_t spellEvent(PCWSTR prefix, WCHAR ** p, i_p avail, DWORD event) {
 PCWSTR txt; is_t aux;

 aux=_snwprintf(*p,*avail,L"%s",prefix); if (aux<0) goto exit0;
 (*p)+=aux; (*avail)-=aux;

 txt=getEvent(event);
 if (txt!=NULL) aux=_snwprintf(*p,*avail,L" %s\r\n",txt);
 else aux=_snwprintf(*p,*avail,L" unknown event (%d)\r\n",event);
 if (aux<0) goto exit0;
 (*p)+=aux; (*avail)-=aux;
 
exit0: **p=0;
 };

v_t spell__nis_entry(nis_entry_p this, HWND edit) {
  WCHAR pool[POOL_SIZE];
  WCHAR * p; i_t avail; is_t aux;
  p=pool; avail=POOL_SIZE;

  if (*this->display!=0) {
    aux=_snwprintf(p,avail,L"%s\r\n",this->display);
    if (aux>0) { p+=aux; avail-=aux; }
  }

  aux=_snwprintf(p,avail,L"%s %s\r\n",this->application,this->args);
  if (aux>0) { p+=aux; avail-=aux; }
   
  switch (this->type) {
  case CNT_EVENT:
    aux=_snwprintf(p,avail,L"system event\r\n");
    if (aux>0) { p+=aux; avail-=aux; }
    spellEvent(L" kind:",&p,&avail,this->event);
    break;
  case CNT_TIME:
    aux=_snwprintf(p,avail,L"time-based\r\n");
    if (aux>0) { p+=aux; avail-=aux; }
    spellSystemTime(L" start at:",&p,&avail,&this->time.start);
    break;
  case CNT_PERIOD:
    aux=_snwprintf(p,avail,L"period-based\r\n");
    if (aux>0) { p+=aux; avail-=aux; }
    spellSystemTime(L" start:",&p,&avail,&this->time.start);
    spellSystemTime(L" stop:",&p,&avail,&this->time.stop);
    break;
  case CNT_CLASSICTIME:
    aux=_snwprintf(p,avail,L"classic time-based\r\n");
    if (aux>0) { p+=aux; avail-=aux; }
    spellSystemTime(L" start at:",&p,&avail,&this->time.start);
    break;
  default:
    aux=_snwprintf(p,avail,L"unknown type (%d)\r\n",this->type);
    if (aux>0) { p+=aux; avail-=aux; }
  };

  SetWindowText(edit,pool);
  SendMessage(edit,EM_SETSEL,0,0);
  SendMessage(edit,EM_SCROLLCARET,0,0);
};
i_t isDuplicate__nis_entry(nis_entry_p l, nis_entry_p r) {
 if (l->type!=r->type || l->event!=r->event) return 0;
 if (mcmp(&l->time,&r->time,sizeof(l->time))!=0) return 0;
 if (!isEqual__spool_datum(&l->extra,&r->extra)) return 0;
 return 1;
 };
